# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Jonahtan Schaeffer <joschaeffer@gmail.com>
# COntributor: Drake Arconis <lightdrake@gmail.com>

pkgbase=jsoncpp
pkgname=('jsoncpp' 'jsoncpp-doc')
pkgver=1.9.4
pkgrel=1
pkgdesc='C++ library for interacting with JSON'
url='https://github.com/open-source-parsers/jsoncpp'
arch=('x86_64')
license=('MIT' 'custom:Public_Domain')
makedepends=('gcc-libs' 'doxygen' 'graphviz' 'python' 'meson')
options=('staticlibs')
source=(https://github.com/open-source-parsers/${pkgbase}/archive/${pkgver}/${pkgbase}-${pkgver}.tar.gz)
sha512sums=('adfd4afbdf6b79bd37edcf0e248f07864994f1c4bcb7431f3b44102490ce467f72381908066655fa486dec12f467af0a11f42f859bbf719895974c7339db7d22')
b2sums=('9a8c52e5d0b78f1593c93bc40f48d3789b031ba0da519c99cce17f1f6e104b24e0ffe88138c25da6dfa250586aeb9e98d00fbf74d9fb9309b29a6d4f17762263')

prepare() {
  cd ${pkgbase}-${pkgver}
  echo "${pkgver}" > version
}

build() {
  cd ${pkgbase}-${pkgver}
  echo "Building shared library..."
  arch-meson --default-library shared build
  ninja -C build

  echo "Building static library..."
  arch-meson --default-library static build-static
  ninja -C build-static

  echo "Building docs..."
  python doxybuild.py \
    --doxygen="$(command -v doxygen)" \
    --with-dot
}

check() {
  cd ${pkgbase}-${pkgver}
  ninja -C build test
  cd test
  python runjsontests.py ../build/jsontestrunner
  python rununittests.py ../build/jsoncpp_test
}

package_jsoncpp() {
  depends=('gcc-libs')
  optdepends=('jsoncpp-doc: documentation')
  provides=('libjsoncpp.so')

  cd ${pkgbase}-${pkgver}
  DESTDIR="${pkgdir}" ninja -C build install
  DESTDIR="${pkgdir}" ninja -C build-static install
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"
}

package_jsoncpp-doc() {
  pkgdesc+=' (documentation)'
  optdepends=('jsoncpp')

  cd ${pkgbase}-${pkgver}
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -dm 755 "${pkgdir}/usr/share/doc/${pkgbase}"
  cp -a dist/doxygen/jsoncpp-api-html-${pkgver} "${pkgdir}/usr/share/doc/${pkgbase}/html"
}

# vim: ts=2 sw=2 et:
